package com.stress.testing.plugin.apache.rocketmq.interceptor;

import com.stress.testing.common.interceptor.AbstractInterceptor;
import com.stress.testing.plugin.apache.rocketmq.hook.PluginSendMessageHook;
import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl;
import org.apache.rocketmq.client.producer.DefaultMQProducer;

import java.lang.reflect.Method;

public class DefaultMQProducerStartInterceptor extends AbstractInterceptor {
    @Override
    public void before(Method method, Object[] args, Object zuper, Object thiz) {
        if (thiz == null || !(thiz instanceof DefaultMQProducer)) {
            return;
        }

        DefaultMQProducer producer = (DefaultMQProducer) thiz;
        DefaultMQProducerImpl defaultMQProducerImpl = producer.getDefaultMQProducerImpl();
        if (defaultMQProducerImpl == null) {
            return;
        }

        defaultMQProducerImpl.registerSendMessageHook(new PluginSendMessageHook());

    }
}
